package com.cloud.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.cloud.domain.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.List;

/**
 * 部门表 sys_dept
 *
 * @author yzj
 */
@Data
@Schema(name = "部门对象", description = "系统管理")
@TableName("sys_dept")
public class SysDept extends BaseEntity {

    @TableId(value = "dept_id", type = IdType.AUTO)
    private Long deptId;

    @Schema(description = "父级部门ID")
    private Long parentId;

    @Schema(description = "祖级列表")
    private String ancestors;

    @Schema(description = "部门名称")
    private String deptName;

    @Schema(description = "显示顺序")
    private String orderNum;

    @Schema(description = "负责人ID")
    private Long leaderId;

    @Schema(description = "部门状态:0正常,1停用")
    private String status;

    @Schema(description = "区域名称")
    private String areaName;

    @Schema(description = "节点类型(0省/市级 1区/县级 2部门 3部门分支)")
    private String nodeType;

    @Schema(description = "删除标识（0代表存 在 1代表删除）", hidden = true)
    @TableField(value = "deleted", fill = FieldFill.INSERT)
    private Integer deleted;

    @Schema(description = "负责人名称")
    @TableField(exist = false)
    private String nickName;

    @Schema(description = "负责人电话")
    @TableField(exist = false)
    private String phone;

    @Schema(description = "负责人邮箱")
    @TableField(exist = false)
    private String email;

    // 1：所有数据权限；2：自定义数据权限；3：本部门数据权限；4：本部门及以下数据权限
    @Schema(description = "数据范围")
    @TableField(exist = false)
    private String dataScope;

    @Schema(description = "父部门名称")
    @TableField(exist = false)
    private String parentName;

    @Schema(description = "子部门", hidden = true)
    @TableField(exist = false)
    private List<SysDept> children = new ArrayList<SysDept>();

    @Schema(description = "区域编码")
    @TableField(exist = false)
    private String areaCode;

    @Schema(description = "父级区域ID")
    @TableField(exist = false)
    private Long areaParentId;

    @NotBlank(message = "部门名称不能为空")
    @Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符")
    public String getDeptName() {
        return deptName;
    }

    @NotBlank(message = "显示顺序不能为空")
    public String getOrderNum() {
        return orderNum;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("deptId", getDeptId())
                .append("parentId", getParentId())
                .append("ancestors", getAncestors())
                .append("deptName", getDeptName())
                .append("orderNum", getOrderNum())
                .append("leaderId", getLeaderId())
                .append("status", getStatus())
                .append("deleted", getDeleted())
                .append("createBy", getCreateBy())
                .append("createTime", getCreateTime())
                .append("updateBy", getUpdateBy())
                .append("updateTime", getUpdateTime())
                .toString();
    }
}
